package org.example.myleet.p1207;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

class Solution {
    public boolean uniqueOccurrences(int[] arr) {
        Map<Integer, Integer> occurrenceMap = new HashMap<>();
        for (int a : arr) {
            if (occurrenceMap.containsKey(a)) {
                Integer occurrence = occurrenceMap.get(a);
                occurrenceMap.put(a, ++occurrence);
            } else {
                occurrenceMap.put(a, 1);
            }
        }
        Set<Integer> occurrenceSet = new HashSet<>();
        for (Map.Entry<Integer, Integer> entry : occurrenceMap.entrySet()) {
            if (occurrenceSet.contains(entry.getValue())) {
                return false;
            } else {
                occurrenceSet.add(entry.getValue());
            }
        }
        return true;
    }
}
